/**
 * This software is distributed under the terms of the MIT License.
 * Copyright (c) 2020 CrobTech.
 * Author: Jason Zhu
 * Contributors: https://gitee.com/JasonZhu2021/tmf8801_tof_demo
 */

#ifndef TCA9548A_GENERIC_H_
#define TCA9548A_GENERIC_H_

/**************************************************************************************
 * INCLUDE
 **************************************************************************************/
#include "stdint.h"
#include "stddef.h"

/**************************************************************************************
 * MCRO DEFINE
 **************************************************************************************/
#define TCA9548A_OK              0
#define TCA9548A_ERROR          -1
#define TCA9548A_DEVICE_ADDR     0xE0
/**************************************************************************************
 * CONSTANTS
 **************************************************************************************/

/**************************************************************************************
 * TYPE DEFINE
 **************************************************************************************/
typedef int32_t (*TCA9548A_Init_Func)(void);
typedef int32_t (*TCA9548A_WriteData_Func)(uint16_t, uint8_t *, uint16_t);
typedef int32_t (*TCA9548A_ReadData_Func)(uint16_t, uint8_t *, uint16_t);

typedef struct 
{
  TCA9548A_Init_Func         Init;
  uint8_t                    Address;
  TCA9548A_WriteData_Func     WriteData;
  TCA9548A_ReadData_Func      ReadData;
}TCA9548A_IO_t;

typedef enum
{
  TCA9548A_IIC_CH0 = 0x01,
  TCA9548A_IIC_CH1 = 0x02,
  TCA9548A_IIC_CH2 = 0x04,
  TCA9548A_IIC_CH3 = 0x08,
  TCA9548A_IIC_CH4 = 0x10,
  TCA9548A_IIC_CH5 = 0x20,
  TCA9548A_IIC_CH6 = 0x40,
  TCA9548A_IIC_CH7 = 0x80,
}IIC_Channel;

typedef struct 
{
  IIC_Channel               ChId;
  TCA9548A_IO_t             IO;          
}TCA9548A_Object_t;
/**************************************************************************************
 * FUNC DEFINE
 **************************************************************************************/
int32_t TCA9548A_RegisterBusIO(TCA9548A_Object_t *pObj, TCA9548A_IO_t *pIO);
int32_t TCA9548A_WriteChID(TCA9548A_Object_t *pObj, IIC_Channel ch);
int32_t TCA9548A_ReadChID(TCA9548A_Object_t *pObj);
#endif /* TMF8801_GENERIC_H_ */
